package org.mydzms.com.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.mydzms.services.login.UserLoginService;
import org.mydzms.services.sms.SmsClientSend;



/**
 * Servlet implementation class MarkServlet
 */
public class MarkServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String tel = request.getParameter("tel");
		
		//制造验证码并存放到session中
		HttpSession session = request.getSession();
		String mark = UserLoginService.VerificationCode();
		session.setAttribute("mark", mark);
		session.setMaxInactiveInterval(60);
		
		//向用户手机发送短信验证码
		SmsClientSend.sendSms(tel, mark);
		//向前台返回信息
		PrintWriter out = response.getWriter();
		out.print(true);
		out.flush();
		out.close();
		
	}
}
